﻿@using Bonobo.Git.Server.Extensions
@model Bonobo.Git.Server.Models.RepositoryDetailModel
@{
    ViewBag.Title = Resources.Repository_Edit_Title;
}
@if (Model == null)
{   
    @Html.Partial("~/Views/Shared/_ItemNotFound.cshtml") 
}
else
{
    <text>
    <h2>@Resources.Repository_Edit_Title</h2>
    @using (Html.BeginForm("Edit", "Repository", FormMethod.Post, new { @class = "uniForm" }))
    {
        if (ViewBag.UpdateSuccess != null && ViewBag.UpdateSuccess)
        {
        <div id="okMsg">
            <p>@Resources.Repository_Edit_UpdateSuccess</p>
        </div>
        }
        @Html.ValidationSummary(false, Resources.Repository_Edit_Fail, new { @id = "errorMsg" })
        @Html.HiddenFor(m => m.Name);
        <fieldset>
            <h3>@Model.Name</h3>
            <div class="ctrlHolder">
                @Html.LabelFor(m => m.Description)
                @Html.TextAreaFor(m => m.Description, new { @class = "textInput medium" })
                <p class="formHint"></p>
            </div>
            <div class="ctrlHolder noLabel">
                @Html.LabelFor(m => m.AllowAnonymous)
                @Html.CheckBoxFor(m => m.AllowAnonymous)
                <p class="formHint">
                    @Resources.Repository_AllowAnonymousHint
                </p>
            </div>
            <div class="ctrlHolder">
                @Html.LabelFor(m => m.Users)
                @{
                    var users = (from u in ViewData["AvailableUsers"] as string[] orderby u
                                          select new SelectListItem() { Value = u, Text = u}).ToArray();
                 }
                
                  @Html.CheckboxListFor(m => m.Users, users, new { @class = "checkboxList medium" }) 
                <p class="formHint">
                    @Resources.Repository_UsersHint
                </p>
            </div>
            <div class="ctrlHolder">
                @Html.LabelFor(m => m.Administrators)
                @{
                    var Administrators = (from u in ViewData["AvailableAdministrators"] as string[] orderby u
                                          select new SelectListItem() { Value = u, Text = u }).ToArray();
                 }
                
                  @Html.CheckboxListFor(m => m.Administrators, Administrators, new { @class = "checkboxList medium" }) 
                <p class="formHint">
                    @Html.ValidationMessageFor(m => m.Administrators)
                    @Resources.Repository_AdministratorsHint
                </p>
            </div>
            <div class="ctrlHolder">
                @Html.LabelFor(m => m.Teams)          
                 @{
                    var teams = (from u in ViewData["AvailableTeams"] as string[] orderby u
                                    select new SelectListItem() { Value = u, Text = u}).ToArray();
                 }
                
                  @Html.CheckboxListFor(m => m.Teams, teams, new { @class = "checkboxList medium" }) 
                <p class="formHint">
                    @Resources.Repository_TeamsHint     
                </p>
            </div>
            <div class="buttonHolder">
                @Html.ActionLink("← " + Resources.Repository_Edit_Back, "Index", null, new { @class = "secondaryAction" })
                <button type="reset" class="secondaryAction">← @Resources.Reset</button>
                <input type="submit" value="@Resources.Repository_Edit_Submit" class="primaryAction" />
            </div>
        </fieldset>
    }
    </text>
}
